<template>
    <div class="execution">
        <basic-container>
            <style-page
                :showTabsRight='false'
                :showTabsHeard='false'
            >
                <!-- <template slot="buttons">
                    <el-button type="primary" size='small'>新增</el-button>
                    <el-button type="primary" size='small'>修改</el-button>
                    <el-button type="primary" size='small'>删除</el-button>
                </template> -->
                <template slot="tabs">
                    <avue-crud ref="crud"
                        v-model="user"
                        :page.sync="page"
                        :data="tableData"
                        :permission="permissionList"
                        :table-loading="tableLoading"
                        :option="tableOption"
                        @on-load="getList"
                        @search-change="searchChange"
                        @refresh-change="refreshChange"
                        @size-change="sizeChange"
                        @current-change="currentChange"
                        @row-update="handleUpdate"
                        @row-save="handleSave"
                        @row-del="rowDel">
                        <template slot="contactTimeForm">
                            <!-- <span>{{scope}}</span> -->
                            <div>
                                <el-select v-model="user.visitDay" placeholder="请选择">
                                    <el-option
                                        v-for="item in callDayList"
                                        :value="item.msgval" :key="item.msgval" :label="item.msgval">
                                    </el-option>
                                </el-select>
                                <el-select v-model="user.visitTime" placeholder="请选择">
                                    <el-option
                                        v-for="item in callTimeList"
                                        :value="item.msgval" :key="item.msgval" :label="item.msgval">
                                    </el-option>
                                </el-select>
                            </div>
                        </template>
                        <!-- <template slot="menuLeft">
                            <el-button type="primary" size='small'>修改</el-button>
                            <el-button type="primary" size='small'>删除</el-button>
                        </template> -->
                        <template slot-scope="scope" slot="menu">
                            <!-- <el-link
                                type="primary"
                                @click.stop="handleEdit(scope.row,'read')"
                                >查看</el-link
                            >
                            <el-link
                                style="margin-left:20px"
                                type="primary"
                                @click.stop="handleEdit(scope.row,'next')"
                                >跟进</el-link
                            >
                            <el-link
                                style="margin-left:20px"
                                type="primary"
                                @click.stop="rowDel(scope.row,scope.index)"
                                >删除</el-link
                            > -->
                            <el-link
                                icon="el-icon-edit"
                                v-if="scope.row.clueStatus!=1"
                                @click.stop="rowStatus(scope.row,scope.index)"
                                style="margin-left:20px;font-size:12px;font-weight:100"
                                type="primary"
                                >转商机
                            </el-link>
                        </template>
                    </avue-crud>
                </template>
            </style-page>
        </basic-container>
    </div>
</template>

<script>
    import {fetchList, getObj, addObj, putObj, delObj, putCustomerclue} from '@/views/saas-business/omscustomerclue/api/omscustomerclue'
    import {tableOption} from '@/views/saas-business/omscustomerclue/const/omscustomerclue'
    import {mapGetters} from 'vuex'

    export default {
        name: 'omscustomerclue',
        data() {
            return {
                user:{},
                callTimeList:[
                    { msg:'任意时间',msgval:'任意时间'},
                    { msg:'9时~12时',msgval:'9时~12时'},
                    { msg:'14时~18时',msgval:'14时~18时'},
                ],
                callDayList:[
                    { msg:'任意时间',msgval:'任意时间'},
                    { msg:'周一',msgval:'周一'},
                    { msg:'周二',msgval:'周二'},
                    { msg:'周三',msgval:'周三'},
                    { msg:'周四',msgval:'周四'},
                    { msg:'周五',msgval:'周五'},
                    { msg:'周六',msgval:'周六'},
                    { msg:'周日',msgval:'周日'},
                ],
                searchForm: {},
                tableData: [],
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 10 // 每页显示多少条
                },
                tableLoading: false,
                tableOption: tableOption,
            }
        },
        computed: {
            ...mapGetters(['permissions']),
            permissionList() {
                return {
                    addBtn: this.vaildData(this.permissions.omscustomerclue_edit, false),
                    delBtn: this.vaildData(this.permissions.omscustomerclue_del, false),
                    editBtn: this.vaildData(this.permissions.omscustomerclue_edit, false),
                };
            }
        },
        methods: {
            rowStatus(row,idx){
                console.log(row);
                // this.$router.push({ name: 'omsbusinessAdd', params: { id: row.id,name:row.custName }})
                this.$confirm('确定进行商机转换?', '提示', {
                confirmButtonText: '确定',
                type: 'warning'}).then( () => {
                    putCustomerclue(row.id).then(res => {
                        console.log(res.data.data);
                        this.$message({
                            type: 'success',
                            message: `操作成功`
                        });
                    })
                }).catch(()=>{})
            },
            getList(page, params) {
                this.tableLoading = true
                fetchList(Object.assign({
                    current: page.currentPage,
                    size: page.pageSize
                }, params, this.searchForm )).then(response => {
                    this.tableData = response.data.data.records
                    this.page.total = response.data.data.total
                    this.tableLoading = false
                }).catch(() => {
                    this.tableLoading=false
                })
            },
            rowDel: function (row, index) {
                this.$confirm('是否确认删除?' , '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    return delObj(row.id)
                }).then(data => {
                    this.$message.success('删除成功')
                    this.getList(this.page)
                })
            },
            handleUpdate: function (row, index, done,loading) {
                putObj(row).then(data => {
                    this.$message.success('修改成功')
                    done()
                    this.getList(this.page)
                }).catch(() => {
                    loading();
                });
            },
            handleSave: function (row, done,loading) {
                addObj(row).then(data => {
                    this.$message.success('添加成功')
                    done()
                    this.getList(this.page)
                }).catch(() => {
                    loading();
                });
            },
            sizeChange(pageSize){
                this.page.pageSize = pageSize
            },
            currentChange(current){
                this.page.currentPage = current
            },
            searchChange(form, done) {
                this.searchForm = form
                this.page.currentPage = 1
                this.getList(this.page, form)
                done()
            },
            refreshChange() {
                this.getList(this.page)
            },
            handleEdit(scope){
                console.log(scope);
            }
        }
    }
</script>
